﻿Imports System.Data.OleDb

Public Class Details
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
    End Sub

   
    Protected Function ShowStars(ByVal numstars As String)
        Dim sb As New System.Text.StringBuilder()
        For index As Integer = 1 To numstars
            sb.Append("*")
        Next
        Return sb
    End Function

    Protected Sub btn_AddTagsToDB_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_addTagsToDB.Click
        Dim sql As String = "INSERT INTO RestaurantTags (Restaurant_fkid, Tag_fkID) VALUES (@f1,@f2)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        conn.Open()
        For Each cb As ListItem In cb_tags.Items
            If cb.Selected = True Then
                'add this to database

                Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
                cmd.Parameters.AddWithValue("@f1", Request.QueryString("ID"))
                cmd.Parameters.AddWithValue("@f2", cb.Value)
                cmd.ExecuteNonQuery()

            End If
        Next

     
    End Sub

    Protected Sub btn_NewTag_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_NewTag.Click
        Dim sql As String = "INSERT INTO Tags (TagName) VALUES (@f1)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_NewTag.Text)
        cmd.ExecuteNonQuery()

        Dim cmd2 As OleDbCommand = New OleDbCommand("SELECT top 1 ID from tags ORDER BY ID Desc", conn)
        Dim dr As OleDbDataReader = cmd2.ExecuteReader()
        dr.read()
        Dim highestID = dr(0)

        Dim associate As String = "INSERT INTO RestaurantTags (Restaurant_fkid, Tag_fkID) VALUES (@f1,@f2)"
        Dim cmd3 As OleDbCommand = New OleDbCommand(associate, conn)
        cmd3.Parameters.AddWithValue("@f1", Request.QueryString("ID"))
        cmd3.Parameters.AddWithValue("@f2", highestID)
        cmd3.ExecuteNonQuery()

    End Sub

    Protected Sub DetailsView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewPageEventArgs) Handles DetailsView1.PageIndexChanging

    End Sub

   
    Protected Sub cb_tags_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cb_tags.SelectedIndexChanged

    End Sub
End Class